package com.intelligent.health.base.utils;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: torlesse-liang
 * @Date: 2022/04/04/14:10
 * @Description: 分页工具类
 */
public class PageUtil {

    /**
     * 计算获取初始记录位置
     *
     * @param pageSize
     * @param currentPage
     * @return
     */
    public static Integer getStartRowNum(Integer pageSize, Integer currentPage) {
        Integer startRowNum;
        if (currentPage <= 1) {
            startRowNum = 0;
        } else {
            startRowNum = (currentPage - 1) * pageSize;
        }
        return startRowNum;
    }

    /**
     * 计算获取结束记录位置
     *
     * @param pageSize
     * @param endPage
     * @return
     */
    public static Integer getEndRowNum(Integer pageSize, Integer endPage) {
        Integer endRowNum;
        if (endPage <= 1) {
            endRowNum = pageSize;
        } else {
            endRowNum = (endPage - 1) * pageSize;
        }
        return endRowNum;
    }
}
